#include<bits/stdc++.h>
using namespace std;
inline int read(){
	int x=0;bool f=0;char ch=getchar();
	while(ch<'0'||ch>'9')f^=(ch=='-'),ch=getchar();
	while('0'<=ch&&ch<='9')x=(x<<1)+(x<<3)+(ch^48),ch=getchar();
	return f?-x:x;
}
const int Maxn=1e6+5;
int n,k,a[Maxn];
int f[Maxn][21];
int fa[Maxn],si[Maxn];
int find(int x){return fa[x]==x?x:fa[x]=find(fa[x]);}
vector<int>G[Maxn];
int vis[Maxn],pd[Maxn];
int dep[Maxn];
inline int kth(int u,int k){
	if(k<0)return u;
	for(int i=20;~i;i--)
		if(k&(1<<i))u=f[u][i];
	return u;
}
int dfn[Maxn],sii[Maxn],cnt;
struct Node{
	int u,dep;
	inline bool operator<(const Node&b)const{return dep<b.dep;}
};
priority_queue<Node>heap;
void dfs(int u,int v){
	dep[u]=dep[v]+1;f[u][0]=v;
	dfn[u]=++cnt;sii[u]=1;
	vis[u]=1;vis[v]=1;
	if(u!=1)heap.push({u,dep[u]});
	for(int i=1;i<=20;i++)f[u][i]=f[f[u][i-1]][i-1];
	for(int y:G[u]){
		dfs(y,u);
		sii[u]+=sii[y];
	}
}
int t[Maxn];
inline void add(int x,int p){
	for(;x<=cnt;x+=x&-x)t[x]+=p;
}
inline int query(int x){
	int res=0;
	for(;x;x-=x&-x)res+=t[x];
	return res;
}
int main(){
	freopen("lost.in","r",stdin);
	freopen("lost.out","w",stdout);
	n=read();k=read();
	for(int i=1;i<=n;i++){
		a[i]=read();
		if(a[i]!=i&&i!=1)G[a[i]].push_back(i);
	}
	if(k==1){
		int cnt=0;
		for(int i=1;i<=n;i++)cnt+=(a[i]!=1);
		printf("%d\n",cnt);
		return 0;
	}int ans=0;
	ans+=(a[1]!=1);
	a[1]=0;
	dep[0]=-1;
	dfs(1,0);
	while(heap.size()){
		int u=heap.top().u;
		heap.pop();
		if(query(dfn[u]))continue;
		pd[u]=1;
		int y=kth(u,k-1);
		if(y>1&&!pd[y]){
			add(dfn[y],1);
			add(dfn[y]+sii[y],-1);
			if(f[y][0]!=1)ans++;//,printf("%d %d\n",y,f[y][0]);
		}
	}
	for(int i=1;i<=n;i++)if(!vis[i])fa[i]=i;
	for(int i=2;i<=n;i++){
		if(!vis[i])fa[find(i)]=find(a[i]);
	}
	for(int i=2;i<=n;i++)
		if(!vis[i])si[find(i)]++;
	for(int i=2;i<=n;i++){
		if(fa[i]==i){
			ans+=(si[i]+k-1)/k;
		}
	}
	printf("%d\n",ans);
	return 0;
}
/*
5 3
2 1 1 3 4
*/
